package leecode;

/**
 * @author cloudJiang
 * @date 2021/10/21 11:15
 */
public class Num66 {
    public static void main(String[] args) {
        int[] nums1 = {1, 2, 4, 5};
        int[] nums2 = new int[5];

        System.arraycopy(nums1, 0, nums2, 1, 4);
        nums2[0] = 10;
        for (int i : nums2) {
            System.out.println(i);
        }
    }

    public int[] plusOne(int[] digits) {
        digits[digits.length - 1]++;

        for (int i = digits.length - 1; i >= 0; i--) {
            if (digits[i] == 10) {
                if (i != 0) {
                    digits[i] = 0;
                    digits[i - 1]++;
                } else {
                    digits[i] = 0;
                    int[] newDigits = new int[digits.length + 1];
                    System.arraycopy(digits, 0, newDigits, 1, digits.length);
                    newDigits[0] = 1;
                    digits = newDigits;
                }
            } else {
                break;
            }
        }

        return digits;
    }

    private static int[] insertElement(int original[], int element, int index) {

        int length = original.length;

        int destination[] = new int[length + 1];

        System.arraycopy(original, 0, destination, 0, index);

        destination[index] = element;

        System.arraycopy(original, index, destination, index + 1, length - index);

        return destination;
    }
}
